/*

 Copyright 2012 Peter Dornbach.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
   
*/

package com.dornbachs.zebra.guitarear;

import android.app.Activity;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.ViewGroup;

public class BaseActivity extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
  	super.onCreate(savedInstanceState);
  	
  	_backgroundIdx = -1;
  	if (savedInstanceState != null) {
  		_backgroundIdx = savedInstanceState.getInt(KEY_BACKGROUND) - 1;
  	}
  	if (_backgroundIdx < 0) {
  		// Set a random background
  		_backgroundIdx = Util.random(BACKGROUND_IDS.length);
  	}
  }
  
  @Override
  public void onStart() {
  	super.onStart();
  	
    ViewGroup root = (ViewGroup)findViewById(android.R.id.content);
    root.getChildAt(0).setBackgroundResource(BACKGROUND_IDS[_backgroundIdx]);
    
    // This tells the system to control the media volume rather than ringtone etc.
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
  }

  @Override
  protected void onSaveInstanceState(Bundle savedInstanceState) {
  	savedInstanceState.putInt(KEY_BACKGROUND, _backgroundIdx + 1);
  	super.onSaveInstanceState(savedInstanceState);
  }

	protected String getLocalNumStr(int num,
			int stringIdSingular, int stringIdPlural) {
		if (num == 1) {
			return getString(stringIdSingular, num);
		} else {
			return getString(stringIdPlural, num);
		}
	}
  
	public static final String INTENT_SELECT_IMPROVE =
			"com.dornbachs.zebra.guitarear.SELECT_IMPROVE";
	public static final String INTENT_SELECT_PRACTICE =
			"com.dornbachs.zebra.guitarear.SELECT_PRACTICE";
	public static final String INTENT_PRACTICE =
    	"com.dornbachs.zebra.guitarear.PRACTICE";
	
	public static final int REQUEST_DEFAULT = 0;
	
	private static final String KEY_BACKGROUND = "BACKGROUND";
	
	private static final int BACKGROUND_IDS [] = {
		R.drawable.bg_acoustic01,
		R.drawable.bg_acoustic02,
		R.drawable.bg_lespaul01,
		R.drawable.bg_gibson01,
	};
	
	private int _backgroundIdx;
}
